package com.hlj.ncp.warehouse.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hlj.ncp.warehouse.entity.Warehouse;
import com.hlj.ncp.warehouse.mapper.WarehouseMapper;
import com.hlj.ncp.warehouse.service.IWarehouseService;
import com.hlj.ncp.common.utils.HljStringUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 仓库信息Service业务层处理
 */
@Service
public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper, Warehouse> implements IWarehouseService {

    /**
     * 查询仓库信息列表
     * 
     * @param warehouse 仓库信息
     * @return 仓库信息
     */
    @Override
    public List<Warehouse> selectWarehouseList(Warehouse warehouse) {
        LambdaQueryWrapper<Warehouse> queryWrapper = new LambdaQueryWrapper<>();
        if (warehouse != null) {
            // 条件过滤
            if (HljStringUtils.isNotBlank(warehouse.getWarehouseName())) {
                queryWrapper.like(Warehouse::getWarehouseName, warehouse.getWarehouseName());
            }
            if (HljStringUtils.isNotBlank(warehouse.getWarehouseCode())) {
                queryWrapper.eq(Warehouse::getWarehouseCode, warehouse.getWarehouseCode());
            }
            if (HljStringUtils.isNotBlank(warehouse.getWarehouseType())) {
                queryWrapper.eq(Warehouse::getWarehouseType, warehouse.getWarehouseType());
            }
            if (HljStringUtils.isNotBlank(warehouse.getStatus())) {
                queryWrapper.eq(Warehouse::getStatus, warehouse.getStatus());
            }
        }
        return list(queryWrapper);
    }

    /**
     * 查询仓库信息详细
     * 
     * @param warehouseId 仓库ID
     * @return 仓库信息
     */
    @Override
    public Warehouse selectWarehouseById(Long warehouseId) {
        return getById(warehouseId);
    }

    /**
     * 新增仓库信息
     * 
     * @param warehouse 仓库信息
     * @return 结果
     */
    @Override
    public boolean insertWarehouse(Warehouse warehouse) {
        return save(warehouse);
    }

    /**
     * 修改仓库信息
     * 
     * @param warehouse 仓库信息
     * @return 结果
     */
    @Override
    public boolean updateWarehouse(Warehouse warehouse) {
        return updateById(warehouse);
    }

    /**
     * 批量删除仓库信息
     * 
     * @param warehouseIds 需要删除的仓库ID
     * @return 结果
     */
    @Override
    public boolean deleteWarehouseByIds(Long[] warehouseIds) {
        return removeByIds(Arrays.asList(warehouseIds));
    }

    /**
     * 删除仓库信息信息
     * 
     * @param warehouseId 仓库ID
     * @return 结果
     */
    @Override
    public boolean deleteWarehouseById(Long warehouseId) {
        return removeById(warehouseId);
    }
} 